import { createRouter, createWebHistory } from 'vue-router'
import BookCase from '@/components/bookCase.vue'
import readTask from '@/components/readTask.vue'
import loginRegister from '@/components/loginRegister.vue'
import knowledgeReview from '@/components/knowledgeReview.vue'
import randomTest from '@/components/examPage.vue'
import userSettings from '@/components/userSettings.vue'
import mindMapGenerator from '@/components/mindMapGenerator.vue'

const routes = [
  {
    path: '/bookCase',
    name: 'BookCase',
    component: BookCase
  },
  {
    path: '/readTask/:id',
    name: 'readTask',
    component: readTask
  },
  {
    path:'/review',
    name:'review',
    component:knowledgeReview
  },
  {
    path:'/login',
    name:'login',
    component:loginRegister
  },
  {
    path:'/randomTest',
    name:'randomTest',
    component:randomTest
  },
  {
    path:'/setting',
    name:'setting',
    component:userSettings
  },
  {
    path:'/mindMap',
    name:'mindMapGenerator',
    component:mindMapGenerator
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 添加路由守卫，用户访问/路由跳转到/bookCase
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next('/bookCase')
  } else {
    next()
  }
})
export default router